package com.beerbear.consumer.config.listener;

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @Author: Beer Bear
 * @Description: 发布订阅的路由模式
 * @Date: 2021/9/3 13:24
 */
@Component
public class SpringRabbitMQListenerForDirect {

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "direct.queue1"),
            exchange = @Exchange(name = "direct",type = ExchangeTypes.DIRECT),
            key = {"red","blue"})
    )
    public void listenDirectQueue1(String msg) {
        System.out.println("接收到Direct路由中Queue1的消息：" + msg);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "direct.queue2"),
            exchange = @Exchange(name = "direct",type = ExchangeTypes.DIRECT),
            key = {"red","yellow"})
    )
    public void listenDirectQueue2(String msg) {
        System.out.println("接收到Direct路由中Queue2的消息：" + msg);
    }
}
